home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / term / vltj5867.lha / VLT / rexx / Intercept.vlt < prev    next >
Text File  |  1994-03-27  |  1KB  |  55 lines

  1. /** Intercept.vlt
  2. *
  3. *   Example program to intercept keystrokes.
  4. *   Changes lower case b's into upper case C's, until you type a lower case a.
  5. *
  6. **/
  7. /*
  8. *   Add libraries if necessary
  9. */
  10. if show("l", "rexxarplib.library") = 0 then do
  11.    check = addlib('rexxsupport.library', 0, -30, 0)
  12.    check = addlib('rexxarplib.library',  0, -30, 0)
  13. end
  14. /*
  15. *   Open a port
  16. */
  17. mp = openport(INTERCEPTPORT)
  18. "message (Now type some lower case b's and other stuff.*NType a lower case a to get out.)"
  19. /*
  20. *   Tell VLT to send us stuff
  21. */
  22. "wedge keystrokes INTERCEPTPORT"
  23. /*
  24. *   Loop until quitflag is 1, waiting for packets
  25. */
  26. do forever
  27.    if quitflag = 1 then leave
  28.    t = waitpkt(INTERCEPTPORT)
  29. /*
  30. *   We got a number of packets. Loop over all of them.
  31. */
  32.    do ff = 1
  33.       p = getpkt(INTERCEPTPORT)
  34.       if c2d(p) = 0 then leave ff
  35.       line = getarg(p)
  36. /*
  37. *   Got a line. It is of the form: KEYSTROKE code qualifier iaddress character
  38. *   parse it out.
  39. */
  40.       parse var line command code qual iaddr char .
  41. /*
  42. *   If we got an "a", quit. If a "b", say that we'll handle this one
  43. *   ourselves by replying a 0 error return and replace it with a capital C!
  44. *   Otherwise return a 1.
  45. */
  46.       if char = 'a' then quitflag = 1
  47.       if char = 'b' then do
  48.          t = reply(p, 0)
  49.          if (char = 'b') then "send (C); emit (C);"
  50.       end
  51.       else t = reply(p, 1)
  52.    end
  53. end
  54.  
  55.